package com.qq.BFMRSE.index;

import java.util.Random;



import Jama.Matrix;

public class indexBuildTool {
	public static int[] getRandomArray(int n)
	{
		int [] restult=new int[n];
		Random random=new Random();
		for(int i=0;i<restult.length;i++)
		{
			restult[i]=random.nextInt(2);
		}
		return restult;
		
	}
	/**
	 * 将整数x分割为result[1]和result[2],使得result[1]+result[2]=x
	 * @param x
	 * @return
	 */
	public static int[]  SpiltInteger(int x)
	{
		int[] result=new int[2];
		Random random=new Random();
		result[0]=random.nextInt(x+1);
		result[1]=x-result[0];
		return result;
	}
	/**
	 *  将double型x分割为result[1]和result[2],使得result[1]+result[2]=x
	 * @param x
	 * @return
	 */
	public static double[]splitDouble(double x)
	{
		double[]result=new double[2];
		Random random=new Random();
		result[0]=random.nextDouble()*x;
		result[1]=x-result[0];
		return result;
	}
	public static double[] getArrayFromMatrix(Matrix matrix)
	{
		double [][]tempArray=matrix.getArray();
		double[]resultArray=new double[tempArray.length];
		if(tempArray[0].length>0)
		{
			for(int i=0;i<tempArray.length;i++)
			{
				resultArray[i]=tempArray[i][0];
			}
		}
		return resultArray;
	}
	/**
	 * 根据均匀分布获取[-c,c]之间的随机数
	 * @param c
	 * @return
	 */
	public static double getUniformRandom(double c)
	{
		double result=0;
		Random random=new Random();
		result=random.nextDouble();
		result=result*2*c-c;
		return result;
	}
	public static void main(String []args)
	{
		double a=Math.sqrt(0.15)*0.05;
		double b=0;
		for(int i=0;i<10;i++)
		{
			double ran=getUniformRandom(a);
			System.out.println(ran);
			b+=ran;
		}
		System.out.println("b="+b);
		
	}
}